﻿using System;
using RootfusAddinContracts;
using RootfusAddinView;
using System.Runtime.Remoting;

namespace RootfusAddinAddinSideAdapters
{
    public class PinDefinitionHostAdapters
    {
        internal static PinDefinition ContractToView(IPinDefinitionContract contract)
        {
            if (!RemotingServices.IsObjectOutOfAppDomain(contract)
                && contract.GetType().Equals(typeof(PinDefinitionViewToContractAdaptor)))
            {
                return ((PinDefinitionViewToContractAdaptor)contract).GetSourceView();
            }
            else
            {
                return new PinDefinitionContractToViewAdaptor(contract);
            }
        }

        internal static IPinDefinitionContract ViewToContract(PinDefinition view)
        {
            if (!RemotingServices.IsObjectOutOfAppDomain(view)
                && view.GetType().Equals(typeof(PinDefinitionContractToViewAdaptor)))
            {
                return ((PinDefinitionContractToViewAdaptor)view).GetSourceContract();
            }
            else
            {
                return new PinDefinitionViewToContractAdaptor(view);
            }
        }
    }
}
